package org.spcloud.service.order;

import java.util.ArrayList;
import java.util.List;

import org.spcloud.service.order.config.message.MessageBinding;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.WeightedResponseTimeRule;
import com.netflix.loadbalancer.ZoneAvoidanceRule;

//@EnableFeignClients
//@EnableEurekaClient
//@SpringBootApplication
@EnableBinding(value = MessageBinding.class)
@SpringCloudApplication
public class OrderApplication {

	public static void main(String[] args) {

		SpringApplication.run(OrderApplication.class, args);
	}

	/**
	 * 注入bean
	 * @return
	 */
	@Bean
	@LoadBalanced
	public RestTemplate restTemplate(){
		return new RestTemplate();
	}

	@Bean
	public IRule irule(){

//		七中负载均衡
//		RoundRobinRule 轮询  按顺序选择服务器列表  默认规则
//		AvailabilityFilteringRule 短路规则
//		WeightedResponseTimeRule  权重规则
//		ZoneAvoidanceRule 区域规则
//		BestAvailableRule 短路规则
//		RandomRule 随机规则
//		Retry 重试规则
		
		return new ZoneAvoidanceRule();
	}
}
